package com.example.test.proxy;

public class main {
    public static void main(String[] args) {
        test1();
    }

    /**
     * 代理模式：在不修改源代码的前提下，借助代理，增强被代理的类或接口
     * 实现方式1: JDK动态代理
     */
    private static void test1() {
        User param = new User("Jack");
        UserService principal = new UserServiceImpl();
        /**
         * 利用principal和invocationHandler生成 proxy
         */
        ProxyInvocationHandler<UserService> invocationHandler = new ProxyInvocationHandler<>();
        invocationHandler.setPrincipal(principal);
        UserService proxy = invocationHandler.getProxy();

        /**
         * proxy代理principal执行方法调用
         */
        User result = proxy.add(param);
        System.out.println(result.toString());
    }
}
